home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / INFO / PCCDEMO.ZIP / COMP1.EXE / JPEG.PRS < prev    next >
Text File  |  1993-12-20  |  22KB  |  353 lines

  1.                                         ôçä àöïï Åêéôöæä Äì ëÅäå ╬╠╬╠╬╠╧╧╬╠╡
  2.          σΣα≤⌠±Σ α±≤ΦΓδΣ                          
  3.                                    │           ûçÇô êÆ ëÅäå?
  4.        ┌┐                          │
  5.        └┘                          │     JPEG (pronounced "jay-peg") is
  6.        ┌┐┌────┐┌────┐┌────┐        │  a standardized  image compression
  7.        │││ ┌┐ ││ ── ││ ┌┐ │        │  mechanism.
  8.        │││ └┘ ││ ───┤│ └┘ │        │     JPEG    stands    for    Joint
  9.        │││ ┌──┘└────┘├──  │        │  Photographic  Experts  Group, the
  10.        ││└─┘         └────┘        │  original  name  of  the committee
  11.        ││  ß√ ≤ε∞ δαφΣ             │  that wrote the standard.
  12.       ┌┘│   Organizer              │
  13.       │ │  Independent             │     JPEG    is     designed    for
  14.       └─┘  JPEG  Group             │  compressing either  full-color or
  15.                                    │  gray-scale  images   of  natural,
  16.                                    │  real-world scenes.  It works well
  17.   " ÷τΣφ α Θ∩Σµ σΦδΣ Φ≥ ∞απΣ σ±ε∞  │  on    photographs,   naturalistic
  18. σ⌠δδ-Γεδε±  πα≤α,  ≤τΣ  Θ∩Σµ ÷Φδδ  │  artwork,  and  similar  material;
  19. ≤√∩ΦΓαδδ√ ßΣ α  σαΓ≤ε± εσ σε⌠± ε±  │  not so well  on lettering, simple
  20. σΦ⌡Σ ≥∞αδδΣ± ≤ταφ α µΦσ σΦδΣ ∞απΣ  │  cartoons, or line drawings.  JPEG
  21. σ±ε∞ ≤τΣ ≥α∞Σ πα≤α. "              │  handles  only  still  images, but
  22.                                    │  there  is   a   related  standard
  23.  
  24.  
  25. called MPEG for motion pictures.   │  JPEG may  be  a problem  for you,
  26.                                    │  even if they are invisible to the
  27.    JPEG is  "lossy," meaning that  │  eye.
  28. the   decompressed   image  isn't  │
  29. quite the  same  as  the  one you  │     A useful  property of  JPEG is
  30. started   with.      (There   are  │  that the degree  of lossiness can
  31. lossless     image    compression  │  be     varied     by    adjusting
  32. algorithms,  but   JPEG  achieves  │  compression  parameters.     This
  33. much greater  compression than is  │  means that  the  image  maker can
  34. possible with  lossless methods.)  │  trade  off   file   size  against
  35. JPEG is designed to exploit known  │  output image  quality.    You can
  36. limitations  of  the  human  eye,  │  make *extremely*  small  files if
  37. notably the fact that small color  │  you don't mind poor quality; this
  38. details aren't  perceived as well  │  is useful  for  applications like
  39. as  small  details  of light-and-  │  indexing      image     archives.
  40. dark.  Thus, JPEG is intended for  │  Conversely, if  you  aren't happy
  41. compressing images  that  will be  │  with the  output  quality  at the
  42. looked at by humans.  If you plan  │  default compression  setting, you
  43. to  machine-analyze  your images,  │  can jack up the quality until you
  44. the  small  errors  introduced by  │  are satisfied,  and accept lesser
  45.                                 
  46.  
  47. compression.                       │  to one.)
  48.                                    │
  49.           ûçÿ öÆä ëÅäå?            │     If   your   viewing   software
  50.                                    │  doesn't  support  JPEG  directly,
  51.    There are two good reasons: to  │  you'll have  to  convert  JPEG to
  52. make  your  image  files smaller,  │  some other format  for viewing or
  53. and  to   store  24-bit-per-pixel  │  manipulating images.  Even with a
  54. color data  instead of 8-bit-per-  │  JPEG-capable  viewer,   it  takes
  55. pixel data.                        │  longer to decode  and view a JPEG
  56.                                    │  image than to view  an image of a
  57.    ∞αΩΦφµ Φ∞αµΣ  σΦδΣ≥ ≥∞αδδΣ± is  │  simpler  format   such   as  GIF.
  58. a big win  for transmitting files  │  Thus, using JPEG is essentially a
  59. across networks and for archiving  │  time/space tradeoff:  you give up
  60. libraries of images.   Being able  │  some time  in  order to  store or
  61. to compress a  2 Mbyte full-color  │  transmit an image more cheaply.
  62. file down  to  100  Kbytes  or so  │
  63. makes a  big  difference  in disk  │     It's  worth  noting  that when
  64. space and transmission time!  (If  │  network or  phone transmission is
  65. you are  comparing GIF  and JPEG,  │  involved, the  time  savings from
  66. the size ratio  is more like four  │  transferring a  shorter  file can
  67.  
  68.  
  69. be greater  than  the  extra time  │  seem  as  obsolete  as black-and-
  70. needed to decompress the file.     │  white MacPaint format does today.
  71.                                    │  Furthermore, for reasons detailed
  72.    ≤τΣ     ≥ΣΓεφπ     σ⌠φπα∞Σφ≤αδ  │  later, JPEG  is  far  more useful
  73. απ⌡αφ≤αµΣ  εσ  Θ∩Σµ  Φ≥  ≤τα≤  Φ≤  │  than  GIF  for  exchanging images
  74. ≥≤ε±Σ≥ σ⌠δδ Γεδε± Φφσε±∞α≤Φεφ: 24  │  among people  with widely varying
  75. bits/pixel  (16  million colors).  │  display hardware.   Hence JPEG is
  76. GIF,  the   other   image  format  │  considerably   more   appropriate
  77. widely used  on Usenet,  can only  │  than  GIF  for  use  as  a Usenet
  78. store 8 bits/pixel  (256 or fewer  │  posting standard.
  79. colors). GIF  is  reasonably well  │
  80. matched  to  inexpensive computer  │     A lot of people are scared off
  81. displays --- most run-of-the-mill  │  by the  term "lossy compression".
  82. PCs can't  display more  than 256  │  But when it comes to representing
  83. distinct  colors   at  once.  But  │  real-world  scenes,  *no* digital
  84. full-color  hardware  is  getting  │  image format  can retain  all the
  85. cheaper all  the  time,  and JPEG  │  information that impinges on your
  86. images  look  *much*  better than  │  eyeball.  In  comparison with the
  87. GIFs on such  hardware.  Within a  │  real-world scene,  JPEG loses far
  88. couple of  years, 8-bit  GIF will  │  less information  than GIF.   The
  89.  
  90.  
  91. technical meaning  of "lossy" has  │  without  visible  loss,  bringing
  92. nothing to do  with this, though;  │  the effective storage requirement
  93. it refers to  loss of information  │  down to 1 to  2 bits/pixel.  30:1
  94. over repeated compression cycles,  │  to 50:1  compression  is possible
  95. a problem that you may or may not  │  with small  to  moderate defects,
  96. care about.                        │  while     for    very-low-quality
  97.                                    │  purposes  such   as  previews  or
  98.        çÄû  ûäïï  âÄäÆ  ëÅäå       │  archive       indexes,      100:1
  99.        éÄîÅæäÆÆ  êîÇåäÆ?           │  compression  is  quite  feasible.
  100.                                    │  An  image  compressed  100:1 with
  101.    Very well indeed, when working  │  JPEG takes up the same space as a
  102. with its  intended type  of image  │  full-color        one-tenth-scale
  103. (photographs and  suchlike).  For  │  thumbnail image,  but  it retains
  104. full-color       images,      the  │  much  more  detail  than  such  a
  105. uncompressed data  is normally 24  │  thumbnail.
  106. bits/pixel.     The   best  known  │
  107. lossless compression  methods can  │     For comparison,  a GIF version
  108. compress such  data about  2:1 on  │  of the same image would start out
  109. average.     JPEG  can  typically  │  by sacrificing most  of the color
  110. achieve 10:1  to 20:1 compression  │  information to  reduce  the image
  111.  
  112.  
  113. to  256  colors  (8  bits/pixel).  │  Because  the  human  eye  is much
  114. This  provides  3:1  compression.  │  more   sensitive   to  brightness
  115. GIF    has    additional    "LZW"  │  variations     than     to    hue
  116. compression  built  in,  but  LZW  │  variations, JPEG can compress hue
  117. doesn't work very well on typical  │  data more heavily than brightness
  118. photographic  data;  at  most you  │  (gray-scale) data.
  119. may get  5:1 compression overall,  │     A  gray-scale   JPEG  file  is
  120. and it's not  at all uncommon for  │  generally   only   about  10%-25%
  121. LZW to be  a net  loss (less than  │  smaller  than  a  full-color JPEG
  122. 3:1 overall compression).          │  file of  similar  visual quality.
  123.    When a JPEG  file is made from  │  But  the  uncompressed gray-scale
  124. full-color data,  using a quality  │  data  is  only  8  bits/pixel, or
  125. setting  just   high   enough  to  │  one-third the  size of  the color
  126. prevent  visible  loss,  the JPEG  │  data,    so     the    calculated
  127. will  typically  be  a  factor of  │  compression ratio  is much lower.
  128. four or  five smaller  than a GIF  │  The threshold of  visible loss is
  129. file made from the same data.      │  often around  5:1 compression for
  130.                                    │  gray-scale images.
  131.    Gray-scale   images   do   not  │     The exact  threshold  at which
  132. compress by  such  large factors.  │  errors become  visible depends on
  133.                                 
  134.  
  135. your  viewing  conditions.    The  │  chrominance subsampling, discrete
  136. smaller an  individual pixel, the  │  cosine   transforms,  coefficient
  137. harder it is to  see an error; so  │  quantization,   and   Huffman  or
  138. errors  are  more  visible  on  a  │  arithmetic entropy  coding.  This
  139. computer  screen   (at  maybe  70  │  article's  too  long  already, so
  140. dots/inch) than on a high-quality  │  I'm not  going  to say  more than
  141. color  printout   (300   or  more  │  that here.
  142. dots/inch).   Thus    a   higher-  │
  143. resolution  image   can  tolerate  │  ûçÇô'Æ  Çïï   ôçêÆ  çÄÄÅïÇ  ÇüÄöô
  144. more  compression  ...  which  is  │  éÄïÄöæ ÉöÇìôêÖÇôêÄì?
  145. fortunate  considering  it's much  │
  146. bigger to start with. The numbers  │     Most people  don't  have full-
  147. quoted  above   are  typical  for  │  color (24 bit  per pixel) display
  148. screen viewing.   Also  note that  │  hardware.     Typical     display
  149. the  threshold  of  visible error  │  hardware stores  8 or  fewer bits
  150. varies somewhat across images.     │  per pixel, so  it can display 256
  151.                                    │  or  fewer  distinct  colors  at a
  152.       çÄû âÄäÆ ëÅäå ûÄæè?          │  time.   To  display  a full-color
  153.                                    │  image, the  computer  must choose
  154.    The  buzz-words  to  know  are  │  an     appropriate     set     of
  155.                                 
  156.  
  157. representative colors and map the  │  algorithm is best for all images.
  158. image into  these  colors.   This  │
  159. process    is    called    "color  │     Since  JPEG  is  a  full-color
  160. quantization". (This is something  │  format, converting  a  color JPEG
  161. of a  misnomer; "color selection"  │  image  for  display  on 8-bit-or-
  162. or "color  reduction" would  be a  │  less   hardware   requires  color
  163. better term.    We're  stuck with  │  quantization.     The  speed  and
  164. the standard usage though.)        │  image quality  of  a  JPEG viewer
  165.                                    │  running  on   such  hardware  are
  166.    Clearly, color quantization is  │  largely    determined    by   its
  167. a lossy  process.   It  turns out  │  quantization  algorithm.   You'll
  168. that for most images, the details  │  see  great   variation  in  image
  169. of    the    color   quantization  │  quality  among  viewers  on 8-bit
  170. algorithm have *much* more impact  │  displays, much  more  than occurs
  171. on the  final image  quality than  │  on 24-bit displays.
  172. do any errors  introduced by JPEG  │     On the other hand, a GIF image
  173. itself (except at the very lowest  │  has already been quantized to 256
  174. JPEG quality settings).  Making a  │  or fewer  colors.   (A GIF *does*
  175. good color quantization algorithm  │  have a specific  number of colors
  176. is a  black  art,  and  no single  │  in its  palette,  and  the format
  177.  
  178.  
  179. doesn't  allow   more   than  256  │  Furthermore, if  the maker didn't
  180. palette entries.)    GIF  has the  │  use    a    high-quality    color
  181. advantage  that  the  image maker  │  quantization   algorithm,  you're
  182. precomputes       the       color  │  out  of  luck  ---  the  image is
  183. quantization,  so  viewers  don't  │  ruined.
  184. have  to;  this  is  one  of  the  │
  185. things  that   make  GIF  viewers  │     For this reason, JPEG promises
  186. faster than  JPEG  viewers.   But  │  significantly     better    image
  187. this is  also  the *disadvantage*  │  quality than  GIF  for  all users
  188. of  GIF:  you're  stuck  with the  │  whose  machines  don't  match the
  189. maker's  quantization.    If  the  │  image  maker's  display hardware.
  190. maker  quantized  to  a different  │  JPEG's full  color  image  can be
  191. number of  colors  than  what you  │  quantized to  precisely match the
  192. can display,  you'll either waste  │  viewer's     display    hardware.
  193. display  capability  or  have  to  │  Furthermore, you will  be able to
  194. quantize again  to further reduce  │  take    advantage    of    future
  195. the  number   of   colors  (which  │  improvements    in   quantization
  196. results  in   much  poorer  image  │  algorithms  (there  is  a  lot of
  197. quality than if you had quantized  │  active research in this area), or
  198. once  from  a  full-color image).  │  purchase better display hardware,
  199.  
  200.  
  201. to  get  a  better  view  of JPEG  │  ±Σ∩±Σ≥Σφ≤Φφµ Φ∞αµΣ≥ Φφ α ∞αΓτΦφΣ-
  202. images you already  have.  With a  │  ΦφπΣ∩ΣφπΣφ≤ σα≥τΦεφ.
  203. GIF,  you're   stuck  forevermore  │
  204. with what was sent.                │     It's sometimes  thought that a
  205.                                    │  JPEG   converted   from   a   GIF
  206.    A  growing  number  of  people  │  shouldn't      require      color
  207. have   better-than-8-bit  display  │  quantization.    This  is  false:
  208. hardware  already:   15-bit  "hi-  │  even when you feed a 256-or-less-
  209. color" PC  displays,  true 24-bit  │  color GIF  into JPEG,  what comes
  210. displays   on   workstations  and  │  out of  the  decompressor  is not
  211. Macintoshes,  etc.     For  these  │  256  colors,   but  thousands  of
  212. people, GIF  is already obsolete,  │  colors.    This  happens  because
  213. as it  cannot represent  an image  │  JPEG's  lossiness   affects  each
  214. to the full capabilities of their  │  pixel  a  little  differently, so
  215. display.   JPEG images  can drive  │  two  pixels   that  started  with
  216. these    displays    much    more  │  identical  colors   will  usually
  217. effectively.                       │  come out  with slightly different
  218.                                    │  colors.  Each original color gets
  219.    Φφ  ≥τε±≤,  Θ∩Σµ  Φ≥  αφ  αδδ-  │  "smeared" into a  group of nearby
  220. α±ε⌠φπ ßΣ≤≤Σ± ΓτεΦΓΣ ≤ταφ µΦσ σε±  │  colors.    Therefore quantization
  221.  
  222.  
  223. is always  required to  display a  │  or  gray-scale,   but  number  of
  224. color  JPEG   on   a  colormapped  │  colors   just   isn't   a  useful
  225. display, regardless  of the image  │  concept for  JPEG, any  more than
  226. source.                            │  it is for a real photograph.
  227.                                    │
  228.    The  same   effect   makes  it  │    ûçäì ÆçÄöïâ ê  öÆä  ëÅäå, Çìâ
  229. nearly meaningless  to talk about  │    ûçäì ÆçÄöïâ ê Æôêéè ûêôç åêà?
  230. the number  of  colors used  by a  │
  231. JPEG image.  Even  if you were to  │     JPEG   is   *not*   going   to
  232. count  the   number  of  distinct  │  displace GIF  entirely;  for some
  233. pixel   values,   different  JPEG  │  types of images,  GIF is superior
  234. decoders would give you different  │  in image  quality, file  size, or
  235. results because of roundoff error  │  both.  One of the first things to
  236. differences.   I occasionally see  │  learn about  JPEG is  which kinds
  237. posted images  described as "256-  │  of images to apply it to.
  238. color JPEG".   This tells me that  │
  239. the poster  (a) hasn't  read this  │     Generally  speaking,  JPEG  is
  240. FAQ  and  (b)  probably converted  │  superior to GIF for storing full-
  241. the JPEG from a GIF.               │  color  or  gray-scale  images  of
  242. JPEGs can be  classified as color  │  "realistic"  scenes;  that  means
  243.  
  244.  
  245. scanned  photographs  and similar  │  visible defects. (One implication
  246. material.        Any   continuous  │  of  this  is  that  large single-
  247. variation  in   color,   such  as  │  color borders are  quite cheap in
  248. occurs in  highlighted  or shaded  │  GIF files,  while  they  are best
  249. areas, will  be  represented more  │  avoided in JPEG files.)
  250. faithfully and  in less  space by  │
  251. JPEG than by GIF.                  │     Computer-drawn   images  (ray-
  252.    GIF does  significantly better  │  traced   scenes,   for  instance)
  253. on  images   with   only   a  few  │  usually fall  between photographs
  254. distinct  colors,  such  as  line  │  and   cartoons    in   terms   of
  255. drawings  and   simple  cartoons.  │  complexity.  The more complex and
  256. Not only is GIF lossless for such  │  subtly  rendered  the  image, the
  257. images, but  it  often compresses  │  more  likely  that  JPEG  will do
  258. them more  than  JPEG  can.   For  │  well on  it.  The  same  goes for
  259. example,  large  areas  of pixels  │  semi-realistic  artwork  (fantasy
  260. that are  all *exactly*  the same  │  drawings and such).
  261. color    are    compressed   very  │
  262. efficiently indeed by  GIF.  JPEG  │     Θ∩Σµ τα≥ α τα±π ≤Φ∞Σ ÷Φ≤τ ⌡Σ±√
  263. can't squeeze  such data  as much  │  ≥τα±∩ ΣπµΣ≥: a  row of pure-black
  264. as GIF  does  without introducing  │  pixels adjacent to a row of pure-
  265.  
  266.  
  267. white pixels, for example.  Sharp  │  16  gray  levels  before  JPEG is
  268. edges tend  to  come  out blurred  │  useful for gray-scale images.  It
  269. unless  you   use  a   very  high  │  should also be  noted that GIF is
  270. quality  setting.     Edges  this  │  lossless for gray-scale images of
  271. sharp   are   rare   in   scanned  │  up to  256 levels,  while JPEG is
  272. photographs,   but   are   fairly  │  not.
  273. common  in  GIF  files:  borders,  │
  274. overlaid   text,    etc.      The  │     If you have a large library of
  275. blurriness     is    particularly  │  GIF images, you  may want to save
  276. objectionable  with  text  that's  │  space by  converting the  GIFs to
  277. only a few  pixels high.   If you  │  JPEG.   This is  trickier than it
  278. have a GIF  with a  lot of small-  │  may seem  --- even  when the GIFs
  279. size  overlaid  text,  don't JPEG  │  contain photographic images, they
  280. it.                                │  are  actually  very  poor  source
  281.                                    │  material  for  JPEG,  because the
  282.    Plain   black-and-white   (two  │  images  have  been color-reduced.
  283. level)  images  should  never  be  │  Non-photographic   images  should
  284. converted to  JPEG;  they violate  │  generally be left in GIF form.
  285. all  of   the   conditions  given  │     Good-quality photographic GIFs
  286. above.   You need  at least about  │  can often  be  converted  with no
  287.  
  288.  
  289. visible quality loss, but only if  │  have claimed.   The quality scale
  290. you know  what you  are doing and  │  is purely  arbitrary; it's  not a
  291. you take the time to work on each  │  percentage of anything.
  292. image  individually.    Otherwise  │
  293. you're likely  to  lose a  lot of  │     In fact, quality scales aren't
  294. image quality  or waste  a lot of  │  even  standardized   across  JPEG
  295. disk  space  ...  quite  possibly  │  programs.   The  quality settings
  296. both.  See  later sections.        │  discussed in  this  article apply
  297.                                    │  to   the   free   JPEG   software
  298.      ûçÇô Çæä  åÄÄâ "ÉöÇïêôÿ"      │  described in  the  next  edition,
  299.         ÆäôôêìåÆ àÄæ ëÅäå?         │  , and to  many  programs based on
  300.                                    │  it. Other JPEG   implementations,
  301.    Most JPEG  compressors let you  │  notably  Apple's  and HSI's,  use
  302. pick  a   file  size   vs.  image  │  completely    different   quality
  303. quality tradeoff  by  selecting a  │  scales;   for  instance,  Apple's
  304. quality setting.   There seems to  │  scale covers 0-4, not 0-100. Some
  305. be widespread confusion about the  │  programs  don't  even  provide  a
  306. meaning   of    these   settings.  │  numeric scale,just "high"/"medium
  307. "Quality 95" does  NOT mean "keep  │  /"low"-style choices.
  308. 95% of the  information", as some  │  (Fortunately,     this    doesn't
  309.  
  310.  
  311. prevent different implementations  │  Q 75  first; if  you see defects,
  312. from exchanging compressed files)  │  then go up.
  313.                                    │     If  the  image  was  less than
  314.    In most cases  the user's goal  │  perfect  quality  to  begin with,
  315. is  to  pick  the  lowest quality  │  you might be able to drop down to
  316. setting, or  smallest  file size,  │  Q   50    without   objectionable
  317. that decompresses  into  an image  │  degradation.  On  the other hand,
  318. indistinguishable     from    the  │  you  might   need  to   go  to  a
  319. original.  This setting will vary  │  *higher* quality setting to avoid
  320. from  one  image  to  another and  │  further loss. Q 85 to 95 is often
  321. from one observer to another, but  │  best  for  converting  GIFs.
  322. here are some rules of thumb.      │
  323.                                    │     Except     for    experimental
  324.    For  good-quality,  full-color  │  purposes, never go  above about Q
  325. source   images,    the   default  │  95; using  Q  100 will  produce a
  326. quality setting  (Q  75)  is very  │  file two or  three times as large
  327. often  the   best   choice.  This  │  as Q 95, but of hardly any better
  328. setting is  about the  lowest you  │  quality.  If you  see a file made
  329. can go  without expecting  to see  │  with Q  100,  it's a  pretty sure
  330. defects in a  typical image.  Try  │  sign that  the maker  didn't know
  331.  
  332.  
  333. what he/she was doing.             │  CONVERTING  GIF  IMAGE S TO JPEG?
  334.                                    │  DOES    LOSS    ACCUMULATE   WITH
  335.    If you want  a very small file  │  REPEATED        COMPRESSION   AND
  336. (say  for   preview  or  indexing  │  DECOMPRESSION?
  337. purposes)  and  are  prepared  to  │  WHY ALL  THE ARGUMENT  ABOUT FILE
  338. tolerate  large   defects,   a  Q  │  FORMATS?
  339. setting in the  range of  5 to 10  │  HOW  DO  I  RECOGNIZE  WHICH FILE
  340. is about right.  Q 2 or so may be  │  FORMAT I HAVE,  AND WHAT  DO I DO
  341. amusing as "op art".               │  ABOUT IT?
  342.                                    │  ISN'T THERE A LOSSLESS JPEG?
  343.                                    │  WHAT ABOUT ARITHMETIC CODING? ñ
  344. In the next edition, we will look  │
  345. at:                                │
  346.                                    │
  347. WHERE  AND  HOW  CAN  I  GET JPEG  │
  348. SOFTWARE?                          │
  349. VIEWERS,   APPLICATION  PROGRAMS,  │
  350. ETC.,   SOURCE   CODE  αφπ   σ±ΣΣ  │
  351. Θ∩Σµ Γε∞∩±Σ≥≥ε±/πΣΓε∞∩±Σ≥≥ε±.      │
  352. WHAT ARE SOME  RULES OF THUMB FOR  │
  353.